<template>
  <view class="su-nav" :class="{sticky:sticky}" :style="{backgroundColor:bgColor}">
    <view class="su-nav-status-bar"></view>
    <view class="su-nav-title-bar" :class="{hasBackBtn:hasBackBtn}" v-if="hasTitle">
      <view :class="['su-nav-back',backBtnType]" @click="back" v-if="hasBackBtn">
        <text class="iconfont icon-back"></text>
      </view>
      <slot></slot>
      <view class="su-nav-title-right">
        <slot name="right"></slot>
      </view>
    </view>
  </view>
</template>

<script>
  export default {
    name: "su-nav",
    props: {
      title: {
        type: String,
        default: ''
      },
      hasTitle: {
        type: Boolean,
        default: true
      },
      hasBackBtn: {
        type: Boolean,
        default: true
      },
      backBtnType: {
        type: String,
        default: 'dark', //dark light
      },
      sticky: {
        type: Boolean,
        default: true
      },
      bgColor: {
        type: String,
        default: 'rgba(0,0,0,0)'
      }
    },
    data() {
      return {};
    },
    methods: {
      back() {
        this.$u.route({
          type: 'back'
        })
      }
    }
  }
</script>

<style lang="scss">
  .su-nav {
    &.sticky {
      position: sticky;
      z-index: 10;
      top: 0;
    }
    
    &-right{
      font-size: 28upx;
      color: #fff;
    }

    &-status-bar {
      height: var(--status-bar-height);
    }

    &-title-bar {
      height: 88upx;
      display: flex;
      justify-content: center;
      align-items: center;
      color: #fff;
      position: relative;
      padding: 0 30upx;
      font-size: 32upx;
      &.hasBackBtn{
        padding-left: 80upx;
        padding-right: 80upx;
      }
    }

    &-back {
      width: 60upx;
      height: 60upx;
      border-radius: 30upx;
      display: flex;
      justify-content: center;
      align-items: center;
      background-color: rgba(0, 0, 0, 0.3);
      color: #fff;
      font-size: 36upx;
      position: absolute;
      left: 20upx;
      top: 50%;
      transform: translate(0, -50%);
      transition: all 0.3s;
      &.light{
        background-color: rgba($color: #000000, $alpha: 0);
        color: #333;
        left: 10upx;
        font-size: 48upx;
      }

      &:active {
        background-color: rgba(0, 0, 0, 0.6);
      }
    }
  }
</style>
